// JavaScript Document
// JavaScript Document
$(function(){
	showQrcode();
});

//显示下载产品二维码图片
function showQrcode() {
	for(var i =1 ; i <= $("#pageSize").val(); i++) {
		$("#yad"+i).hover(function(){
			$(this).find('div').show();
		},function(){
			$(this).find('div').hide();
		});
		$("#yap"+i).hover(function(){
			$(this).find('div').show();	
		},function(){
			$(this).find('div').hide();
		});
	}
}


//客户端下载分页查询
function phoneReload(page) {
	var data_param = {
		downloadId: $("#downloadId").val(),
		page : page
	};
	$.ajax({
		type:"POST",
		url:"/service/download/ajaxPage",
		data:data_param,
		async:false,
		dataType:"json",
		success:function(data){
			$('#page').val(data.page);
			$('#pageCount').val(data.pageCount);
			
			//手机客户端下载产品查询
			var phone = '<p style="visibility:hidden;">占位符</p>';
			$("#phone").empty();
			$.each(data.dpVos,function(index,dpv){
				if(data.dpVos.length > 0) {
					phone += '<div class="phodown_mok cle">'+
							 '<div class="img_con"><img src="'+dpv.product.productImg+'" width="100px" height="100px"></div>'+
						     '<div class="text_con">'+
						     '<h3>'+dpv.product.productName+'</h3>'+
						     '<p>'+dpv.product.productSpecialtyBrief+'</p>'+
						     '<div class="btn_con cle">';
					
					$.each(dpv.pdv,function(index1,pdv){
						if(pdv.downloadWayId == 1) {
							phone += '<div class="android">';
						}else if(pdv.downloadWayId == 2){
							phone += '<div class="apple">';
						}else {
							phone += '<div class="pc">';
						}
						phone += '<a href="'+pdv.downloadUrl+'" class="btn"><i class="icon"></i><span>'+pdv.downloadWayName+'</span></a>';
						if(pdv.downloadWayId == 1) {
							phone += '<a href="#" class="ewm" id="yad'+ (index + 1) +'"><img src="'+pdv.productDownloadQrcode+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmad'+ (index + 1) +'" style="display: none;"><img src="'+pdv.productDownloadQrcode+'" width="160" height="160"/></div></a>';
						}else if(pdv.downloadWayId == 2){
							phone += '<a href="#" class="ewm" id="yap'+ (index + 1) +'"><img src="'+pdv.productDownloadQrcode+'" width="16" height="16" class="small"/><div class="tc_ewm" id="ewmap'+ (index + 1) +'" style="display:none;"><img src="'+pdv.productDownloadQrcode+'" width="160" height="160"/></div></a>';
						}
						phone += '</div>';
					})
					phone += '</div></div></div>';
				}
				
			})
			phone +='<div class="page mt20" align="center">共'+data.totalRows+'条记录 '+data.page+'/'+data.pageCount+'页&nbsp;'+
					'<a href="javascript:phoneReload(1)">&nbsp;首页</a> <a onclick="javascript:ajaxPageUp('+data.page+')">上一页</a>&nbsp;'+
					'<a onclick="javascript:ajaxPageDown('+data.page+');">&nbsp;下一页</a>&nbsp;'+
					'<a href="javascript:phoneReload('+data.pageCount+')" >尾页</a>&nbsp;&nbsp;第&nbsp;&nbsp;'+
					'<select onchange="ajax2Page()" id="currPage">';
			for(var i = 1; i <= data.pageCount; i++) {
				phone += '<option value="'+i+'" ';
				if(data.page == i) {
					phone += 'selected="selected"';
				}
				phone += '>'+i+'</option>';
			}
			phone += '</select>&nbsp;页</div>';		
			$("#phone").append(phone);
			
		}
	})
	
	showQrcode();
}

function ajax2Page() {
	phoneReload($('#currPage').val());
}

//向上翻页
function ajaxPageUp(page) {
	if(page == 1) {
		BSTYUN.dialog.warn("已经是第一页");
		return;
	}else {
		var num = parseInt(page) - 1;
		phoneReload(num);
	}
}

//向下翻页
function ajaxPageDown(page) {
	if(page == $("#pageCount").val()) {
		BSTYUN.dialog.warn("已经是最后一页");
		return;
	}else {
		var num = parseInt(page) + 1;
		phoneReload(num);
	}
}
